package com.hey.feign.userservice;

import com.hey.common.enums.CodeStatus;
import com.hey.common.result.BaseResult;
import com.hey.common.result.MultiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "user-service",fallback = UserServiceFeign.Fallback.class)
public interface UserServiceFeign {

    @RequestMapping(value = "/user/find/all",method = RequestMethod.GET)
    MultiResult findAllUser();

    @Component
    class Fallback implements UserServiceFeign{
        @Autowired
        private DiscoveryClient discoveryClient;

        @Override
        public MultiResult findAllUser() {
            MultiResult baseResult = new MultiResult();
            baseResult.setMsg(CodeStatus.ERROR);
            baseResult.setData(discoveryClient.getServices()+"接口失败啦");
            return baseResult;
        }
    }
}
